import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:proj_sfv/http/requests.dart';

class MyNotification extends StatelessWidget {

  final String content;
  final List<Widget> actions;

  MyNotification(this.content, this.actions); // 提示内容

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: Text("提示"),
      content: Text(content ?? ""),
      actions: actions,
    );
  }
}

List<Widget> oneConfirmButton(BuildContext context) => [
  TextButton(onPressed: () => Navigator.pop(context), child: Text("确认")),
];

// 修改内容
class ModifyDialog extends StatefulWidget {

  String oldValue;
  String filedName;
  @override
  _ModifyDialogState createState() => _ModifyDialogState();

  ModifyDialog(this.oldValue, this.filedName);
}

class _ModifyDialogState extends State<ModifyDialog> {
  final TextEditingController _textController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: Text('编辑 ${widget.filedName}'),
      content: TextField(
        controller: _textController,
        autofocus: true,
        decoration: InputDecoration(
          hintText: widget.oldValue,
        ),
      ),
      actions: <Widget>[
        TextButton(
          child: Text('取消'),
          onPressed: () {
            Navigator.pop(context, null);
          },
        ),
        TextButton(
          child: Text('提交'),
          onPressed: () {
            String text = _textController.text;
            // 在此处执行提交操作
            Navigator.pop(context, text);
          },
        ),
      ],
    );
  }
}
